package com.ticket.controller;

import com.ticket.pojo.PageBean;
import com.ticket.pojo.Plane;
import com.ticket.service.PlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@ResponseBody
@RequestMapping("/plane")
public class PlaneController {
    @Autowired
    private PlaneService planeService;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/{currentPage}/{pageSize}")
    public PageBean<Plane> selectByPage(@PathVariable int currentPage, @PathVariable int pageSize){
        System.out.println("plane selectByPage is running ... ");
        PageBean<Plane> planePageBean = planeService.selectByPage(currentPage, pageSize);
        System.out.println(planePageBean);
        return planePageBean;
    }

    @PostMapping("/{currentPage}/{pageSize}")
    PageBean<Plane> selectByPageAndCondition(@PathVariable int currentPage,@PathVariable int pageSize,@RequestBody Plane plane){
        System.out.println("plane selectByPageAndCondition is running ... ");
        System.out.println(plane);
        PageBean<Plane> planePageBean = planeService.selectByPageAndCondition(currentPage, pageSize, plane);
        System.out.println(planePageBean);
        return planePageBean;
    }
    @PostMapping
    public String add(@RequestBody Plane plane) {
        System.out.println("plane add is running ... ");
        planeService.add(plane);
        return "success";
    }
    @PutMapping
    public String update(@RequestBody Plane plane){
        System.out.println("plane update is running ... ");
        System.out.println(plane);
        planeService.update(plane);
        return "success";
    }
    @RequestMapping("/login")
    public int findPlane(@RequestBody Plane plane){
        System.out.println("plane findPlane is running ... ");
        System.out.println(plane);
        return 0;
//        return planeService.findPlane(plane);
    }
    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable int id){
        System.out.println("plane deleteById is running ... ");
        System.out.println(id);
        planeService.deleteById(id);
        return "success";
    }

    @DeleteMapping
    public String deleteByIds(@RequestBody int[] ids){
        System.out.println("plane deleteByIds is running ... ");
        System.out.println(ids);
        planeService.deleteByIds(ids);
        return "success";
    }
}
